package com.anan.exception;

import com.anan.constants.Constants;
import com.anan.utils.ComResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author anan
 * @date 2023/03/15/15:47
 **/

@RestControllerAdvice
public class GlobalExceptionHandle {

    @ExceptionHandler(SystemException.class)
    public ComResult doSystemException(SystemException e){
        e.printStackTrace();//打印异常信息
        //记录日志
        //返回消息给运维
        //发送邮件给开发人员
        return new ComResult(e.getCode(),e.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public ComResult doBusinessException(BusinessException e){
        e.printStackTrace();//打印异常信息
        return new ComResult(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ComResult doException(Exception e) {
        e.printStackTrace();//打印异常信息
        //记录日志
        //返回消息给运维
        //发送邮件给开发人员
        return new ComResult(Constants.EXCEPTION_CODE.SYSTEM_UNKNOW_ERR, "您的网络有波动，请稍后重试！");//直接甩锅给用户
    }
}
